package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuaimacode.kframework.mybatis.mapper.finance.AgentAccountDetailMapper;
import com.kuaimacode.kframework.mybatis.models.finance.AgentAccountDetail;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class AgentAccountDetailService extends ServiceImpl<AgentAccountDetailMapper, AgentAccountDetail> {

    @Async
    public void insertAgentAccountDetail(String agentId, String tranType, String desc, BigDecimal income, BigDecimal bal, String orderNo){
        try {
            AgentAccountDetail accountDetail = new AgentAccountDetail();
            accountDetail.setAgentId(agentId);
            accountDetail.setTranType(tranType);
            accountDetail.setTranBal(bal.add(income));
            accountDetail.setAmount(income);
            accountDetail.setInOut("1");//收入
            accountDetail.setTranDesc(desc);
            accountDetail.setTranTime(new Date());
            accountDetail.setTranId(orderNo);
            this.save(accountDetail);
        }catch (Exception ex){
            System.out.println("插入账户明细表异常");
        }
    }
}
